package avicit.im.lantop.basic.archiveclassmanager.action.service.impl;

import java.util.Map;

import avicit.im.lantop.basic.archiveclassmanager.action.service.CommonManagerIntfsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import avicit.im.lantop.common.service.CommonManagerIntfsService;
import avicit.platform6.api.sysmenu.SysMenuAPI;
import avicit.platform6.api.sysmenu.dto.SysMenuTl;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.service.ServiceBase;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：王旭</p>
 * <p>邮箱：wangxu01@avicit.com</p>
 * <p>创建时间： 2016-1-19</p>
 * <p>类说明：档案公共接口实现类</p>
 * <p>修改记录： </p>
 */
@Service
public class CommonManagerIntfsServiceImpl extends ServiceBase implements CommonManagerIntfsService {

	@Autowired(required = false)
	SysMenuAPI sysMenuAPI;

	/**
	 * 获取菜单信息
	 * @author 王旭 
	 * @param menuCode,appId,languageCode
	 * @return
	 * @throws
	 */
	public String getMenuNameByCodeByIntfs(String menuCode, String appId, String languageCode) throws Exception {
		String menuId = sysMenuAPI.getSysMenuIdByCode(menuCode, appId);
		String menuName = "";
		SysMenuTl sysMenuTl = sysMenuAPI.getSysMenusTlById(menuId, languageCode);
		if (null != sysMenuTl) {
			menuName = sysMenuTl.getName();
		}
		return menuName;
	}

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	/**
	 * 将上级组织应用下的归档模版数据拷贝至新组织应用下
	 * @param orgId  组织ID
	 * @param deptId 部门ID
	 * @param sysId 系统ID
	 * @param param 其它参数
	 * 					key: SOURCE_IDENTITY_ID  源组织应用ID
	 * 					  	 TARGET_IDENTITY_ID  目标组织应用ID
	 * 					  	 CREATED_BY			   创建人
	 *    					 CREATION_DATE       创建时间
	 *    					 IP 			     IP地址
	 *    					 VERSION			   版本号
	 * @throws Exception void
	 */
	public void doCopyIdentityDatasByParam(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		// 验证组织ID是否为null或""
		if (orgId == null || orgId.equals("")) {
			throw new Exception("调用方法时orgId参数不存在，请检查！");
		}
		// 验证部门ID是否为null或""
		if (deptId == null || deptId.equals("")) {
			throw new Exception("调用方法时deptId参数不存在，请检查！");
		}
		// 验证系统ID是否为null或""
		if (sysId == null || sysId.equals("")) {
			throw new Exception("调用方法时sysId参数不存在，请检查！");
		}
		// 验证参数集合param是否为null
		if (null == param) {
			throw new Exception("调用方法时param参数为null，请检查！");
		}
		// 验证param集合中中是否存在SOURCE_IDENTITY_ID 源组织应用ID
		String sourceIdentityId = "";
		if (param.containsKey("SOURCE_IDENTITY_ID")) {
			sourceIdentityId = (String) param.get("SOURCE_IDENTITY_ID");
		} else {
			throw new Exception("调用方法时SOURCE_IDENTITY_ID参数不存在，请检查！");
		}
		// 验证param集合中中是否存在TARGET_IDENTITY_ID 目标组织应用ID
		String targetIdentityId = "";
		if (param.containsKey("TARGET_IDENTITY_ID")) {
			targetIdentityId = (String) param.get("TARGET_IDENTITY_ID");
		} else {
			throw new Exception("调用方法时TARGET_IDENTITY_ID参数不存在，请检查！");
		}

		// 验证param集合中中是否存在CREATED_BY 创建人
		String createdBy = "";
		if (param.containsKey("CREATED_BY")) {
			createdBy = (String) param.get("CREATED_BY");
		} else {
			throw new Exception("调用方法时CREATED_BY参数不存在，请检查！");
		}

		// 验证param集合中中是否存在CREATED_DATE 创建时间
		String createdDate = "";
		if (param.containsKey("CREATED_DATE")) {
			createdDate = (String) param.get("CREATED_DATE");
		} else {
			throw new Exception("调用方法时CREATED_DATE参数不存在，请检查！");
		}

		// 验证param集合中中是否存在IP IP地址
		String ipAddress = "";
		if (param.containsKey("IP")) {
			ipAddress = (String) param.get("IP");
		} else {
			throw new Exception("调用方法时IP参数不存在，请检查！");
		}

		// 验证param集合中中是否存在VERSION 版本号
		String version = "";
		if (param.containsKey("VERSION")) {
			version = (String) param.get("VERSION");
		} else {
			version = "0";
		}
	}
}
